<?php

/**
 * Авторизация на VK
 * 
 * @author 
 * @copyright 2010
 */

	class Auther
	{
		static public function authorized($flashVars)
		{ 
			/*if($_SESSION['auth']){
			     return true;
			}else
            
            */
            #return $flashVars;
            #return $flashVars['auth_key']." == ".auther::getAuthKey($flashVars);
            if (($flashVars['is_app_user'] == 1) && ($flashVars['auth_key'] == auther::getAuthKey($flashVars)))
			{
				//$_SESSION['auth'] = true;
                return true;
                #return $flashVars['auth_key']." == ".auther::getAuthKey($flashVars); 
			}
			else
			{
				return false; 
                #return $flashVars['auth_key']." == ".auther::getAuthKey($flashVars);
			}   
		}
		
        
        static function sessionStart($user, $flashVars){
            $_SESSION['auth'] = true;
            $_SESSION['userId'] = $user;
            foreach($flashVars as $key => $val){
                $_SESSION[$key] = $val;    
            }
            
        }
        static function checkAuth($user){
            /*if(DEBUG != false){
                return true;
            }*/                        
            
            if(isset($_SESSION['auth']) && $_SESSION['userId'] == $user){
                
                $sql = "SELECT `sessid` FROM `".PREFIX_TABLE."users` WHERE `kontaktid` = '".$user."' ";
                if( !$result = DBConnect::query($sql) ) return false;
                $arr = DBConnect::getOne($result);
                if( $arr['sessid'] == '' ){
                    $s = new Session();
                    $s->deleteMySession();
                }
                
                return true;
            }else{
                return false;
            }
        }
        
        
        static private function getAuthKey($array)
		{
			return md5($array["api_id"]. '_' . $array["viewer_id"] . '_' . SECURE_CODE);
		}
        
        
	}

?>